package hadoop.mr04;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class T_mapper extends Mapper<LongWritable, Text, person, NullWritable> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, person, NullWritable>.Context context) throws IOException, InterruptedException {
        String[] split = value.toString().split(",");
        String name = split[1];
        if (split[2].equals("性别") == false && split[5].length() > 0) {
            int sex = Integer.parseInt(split[2]);
            int sumTag = Integer.parseInt(split[3]) + Integer.parseInt(split[4])
                    + Integer.parseInt(split[5]) + Integer.parseInt(split[6])
                    + Integer.parseInt(split[7]) + Integer.parseInt(split[8])
                    + Integer.parseInt(split[9]) + Integer.parseInt(split[10]);
            person person = new person(name, sex, sumTag);
            System.out.println(person.toString());
            context.write(person, NullWritable.get());
        }
    }
}
